package com.yuchen.ishop.service.goods;

import com.yuchen.core.MyPager;
import com.yuchen.ishop.entity.Goods;
import com.yuchen.jaxrs.restclient.RestClientUtils;
import com.yuchen.jaxrs.Responses;
import com.yuchen.utils.config.ConfigUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.ws.rs.core.GenericType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class GoodsRestClient {

    private final static Logger LOG = Logger.getLogger(GoodsRestClient.class);

    public Responses insert(Goods goods) {
        String url = ConfigUtils.config.get("goods_insert");
        Responses responses = RestClientUtils.post(Responses.class, goods, url);
        return responses;
    }

    public MyPager finds(Map params) {
        String url = ConfigUtils.config.get("goods_find");
        return RestClientUtils.post(MyPager.class, params, url);

    }


    public Goods get(Long id) {
        String url = ConfigUtils.config.get("goods_get");
        Map map = new HashMap(1);
        map.put("id",id);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.get(Goods.class, url);
    }

    public Responses update(Goods goods) {
        String url = ConfigUtils.config.get("goods_update");
        Responses responses = RestClientUtils.post(Responses.class, goods, url);
        return responses;
    }

    public Responses delete(Long goodsId) {
        String url = ConfigUtils.config.get("goods_delete");
        Map map = new HashMap(1);
        map.put("id",goodsId);
        url = RestClientUtils.url(url,map);
        Responses responses = RestClientUtils.delete(Responses.class, url);
        return responses;
    }


    public Boolean isAccessGoods(Long goodsId) {
        String url = ConfigUtils.config.get("goods_isAccessGoods");
        Map map = new HashMap(1);
        map.put("id",goodsId);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.get(Boolean.class, url);
    }

    public MyPager findByLimit(Map params) {
        String url = ConfigUtils.config.get("goods_findByLimit");
        return RestClientUtils.post(MyPager.class, params, url);

    }

    public Responses lockGoods(Long id) {
        String url = ConfigUtils.config.get("goods_lockGoods");
        return RestClientUtils.post(Responses.class, id, url);
    }

    public Responses offGoods(Long id) {
        String url = ConfigUtils.config.get("goods_offGoods");
        return RestClientUtils.post(Responses.class, id, url);
    }

    public Responses upGoods(Long id) {
        String url = ConfigUtils.config.get("goods_upGoods");
        return RestClientUtils.post(Responses.class, id, url);
    }

    public Responses refresh(Long id) {
        String url = ConfigUtils.config.get("goods_refresh");
        return  RestClientUtils.post(Responses.class, id, url);
    }
}
